package com.huluobo.high3demo.register;

import android.util.Log;

import androidx.lifecycle.MutableLiveData;

import com.huluobo.mvvm.baen.UserBeanResult;
import com.huluobo.mvvm.model.BaseRepo;

import io.reactivex.Observer;
import io.reactivex.Scheduler;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
import okhttp3.RequestBody;

/**
 * 注册的Model层
 * Created by LC on 2023/9/15.
 */
public class RegisterRepo extends BaseRepo {
    public void register(RequestBody body,
                         MutableLiveData<UserBeanResult.UserBean> success, MutableLiveData<String> failed) {
        apiService.register(body)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<UserBeanResult>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(UserBeanResult userBeanResult) {
                        success.setValue(userBeanResult.getData());
                    }

                    @Override
                    public void onError(Throwable e) {
                        failed.setValue(e.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }
}
